package com.clay.user.controller;

import com.clay.appointment.common.response.Result;
import com.clay.appointment.utils.IpUtils;
import com.clay.appointment.utils.RequestContextUtils;
import com.clay.appointment.vo.user.LoginVo;
import com.clay.user.service.UserInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author : clay
 * @Description: 用户操作接口
 * @Date: Create in 15:43 2021/8/25
 * @Modified By:
 */
@RestController
@RequestMapping("/user")
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "会员登录")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo) {
        HttpServletRequest request = RequestContextUtils.getRequest();
        loginVo.setIp(IpUtils.getIpAddr(request));
        Map<String, Object> data = userInfoService.loginUser(loginVo);
//        RequestContextUtils.getResponse().addCookie(new Cookie("token",data.get("token").toString()));
//        data.remove("token");
        return Result.success(data);
    }

}
